// https://leetcode-cn.com/problems/palindrome-partitioning/
// 131. 分割回文串

#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <limits.h>

using namespace std;

// struct ListNode {
//     int val;
//     ListNode *next;
//     ListNode() : val(0), next(nullptr) {}
//     ListNode(int x) : val(x), next(nullptr) {}
//     ListNode(int x, ListNode *next) : val(x), next(next) {}
// };

// struct TreeNode {
//     int val;
//     TreeNode *left;
//     TreeNode *right;
//     TreeNode() : val(0), left(nullptr), right(nullptr) {}
//     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
//     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
// };



class Solution {
public:
    vector<vector<string>> partition(string s) {
        backtrack(s, 0);
        return result;
    }
private:
    vector<vector<string>> result;
    vector<string> group;

    void backtrack(string s, int start_index) {
        if (start_index >= s.size()) {
            result.push_back(group);
            return;
        }

        for (int i = start_index; i < s.size(); i++) {
            if (IsPartition(s, start_index, i)) {
                string str = s.substr(start_index, i - start_index + 1);
                group.push_back(str);
            } else {
                continue;
            }
            backtrack(s, i + 1);
            group.pop_back();
        }
    }

    bool IsPartition(string s, int start, int end) {
        for (int i = start, j = end; i < j; i++, j--) {
            if (s[i] != s[j]) {
                return false;
            }
        }
        return true;
    }
};



int main() {
    Solution obj = Solution();
}